import { createRouter, createWebHistory } from 'vue-router';
import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper';
const baseURL = import.meta.env.VITE_BUILD_BASE_URL;
const appCode = import.meta.env.VITE_APPCODE;
const getRouter = base => {
  const router = createRouter({
    // 若是乾坤，则为主应用传过来路由，否则为当前应用路由
    history: createWebHistory(qiankunWindow.__POWERED_BY_QIANKUN__ ? base : baseURL + appCode),
    routes: [
      {
        path: '/',
        redirect: '/menu',
        component: () => import('@/layout'),
        children: [
          {
            path: '/menu',
            name: 'menu',
            component: () => import('@/views/menu'),
          },
          // 微应用管理
          {
            path: '/microApp',
            name: 'microApp',
            component: () => import('@/views/microApp'),
          },
          // 微应用路由管理
          {
            path: '/microAppRouter',
            name: 'microAppRouter',
            component: () => import('@/views/microAppRouter'),
          },
          // 微应用路由添加
          {
            path: '/microAppRouter/add',
            name: 'microAppRouterAdd',
            component: () => import('@/views/microAppRouter/add'),
          },

          // 图标管理
          {
            path: '/icon',
            name: 'icon',
            component: () => import('@/views/icon'),
          },

          // 角色列表
          {
            path: '/role',
            name: 'roleList',
            component: () => import('@/views/role'),
          },
          // 用户列表
          {
            path: '/user',
            name: 'userList',
            component: () => import('@/views/user'),
          },
        ],
      },
    ],
  });

  return router;
};
export default getRouter;
